package myframe.event;



import java.util.HashSet;
import java.util.Set;

import lombok.Data;

@Data
public class SaySource {
	String name;
	
	Set<SayListener> sayListenerSet = new HashSet<>();
	
	public void addListenters(SayListener listener){
		sayListenerSet.add(listener);
	}
	
	
	public void notifi(){
		sayListenerSet.forEach(listener ->{
			listener.sayName(new SayEvent(this));
		});
	}
	
	public void setName(String name){
		this.name = name;
		notifi();
	}
	
	public static void  main(String[] args){
		SaySource saySource = new SaySource();
		saySource.setName("1222");
		String a ="bbb";
		saySource.addListenters(new SayListener(){
            public void sayName(SayEvent e) {  
                super.sayName(e);  
                System.out.println(a);
            }
		});
		saySource.setName("4555");
		saySource.setName("4666");
		saySource.setName("4777");
		saySource.setName("4888");
		
	}
	

}
